package online.shenjian.hadoop.partitionerSort;

import online.shenjian.hadoop.sort.FlowBean;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Partitioner;

/**
 * @author shenjian
 * @since 2023/2/11
 */
public class ProvincePartitioner extends Partitioner<FlowBean, Text> {

    @Override
    public int getPartition(FlowBean flowBean, Text text, int numPartitions) {
        // Text是手机号
        String phone = text.toString().substring(0, 3);
        // 注意分区号需要连续，从0开始分区
        int partition;
        if ("136".equals(phone)) {
            partition = 0;
        } else if ("137".equals(phone)) {
            partition = 1;
        } else if ("138".equals(phone)) {
            partition = 2;
        } else if ("139".equals(phone)) {
            partition = 3;
        } else {
            partition = 4;
        }
        return partition;
    }
}
